#include <Function For Localize.au3>

Sleep(40000)
Local $iMoreSleepTime = 1000

If GetOSLanguage() == 'Korean' Or GetOSLanguage() == 'Slovak' Then
	
	Sleep(200000)
	
EndIf

CreatePath($PERFORM_RESULT_FOLDER_PATH)

; Install PM -------------------------------------------------------------------------------

Run($SETUP_EXE_PATH) 

Sleep($INSTALLER_SELF_EXTRACT_TIME)

Sleep(10000)

;Still wait the self-extract.
$isESDVersion = False

If ControlGetHandle(WinGetHandle(''),'', 'msctls_progress321') <> "" Then
	
	$isESDVersion = True
	
EndIf

If $isESDVersion Then
	
	Sleep(90000)
	
EndIf

$isInstallNotnetBeggin = False

;For install notNet in the begnnig
If ControlGetHandle(WinGetHandle(''),'', 'SysListView321') <> "" Then
	
	Sleep(3000)
	
	Local $title = WinGetTitle(WinGetHandle(''))
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Install Commonpent At Begnning.jpg', WinGetHandle($title))
	
	ControlClick($title,'', 'Button1')
	
	Sleep(5000)
	
	$isInstallNotnetBeggin = True
	
Else
	
	$iMoreSleepTime = 100000
	
EndIf

If $isInstallNotnetBeggin Then
	
	While ControlGetHandle($title,'', 'SysListView321') <> ""
		
		WinActive($title)
		
		Sleep(5000)
		
	WEnd
	
	Sleep(15000)
EndIf

BeforeWelcomeDialog()

ClickMouseToSetfocus()

ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Welcome Dialog.jpg', WinGetHandle(''))

If ClickCancelButton() Then
	
	Sleep(1000)

	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Exit Setup Dialog.jpg', WinGetHandle(''))
	
	ControlClick('', '', 'Button2')   ;Click NO button on exit setup dialog.
	
	Sleep(1500)
	
	WinActivate("[CLASS:#32770]")
EndIf

CliclkNextButton()

If IsHasNextStep() == 'NO' Then Exit
	
Switch DetermineCurrentDialog()
	
Case 'LicenseDialog'   ;welcome -> license 
	
	LicenseDialogTest() 
	
	CliclkNextButton() 
	
	If IsHasNextStep() == 'NO' Then Exit
		
	Switch DetermineCurrentDialog()
		
	Case 'SNDialog'   ;welcome -> license -> SN
		
		SNDialogTest()
		
		CliclkNextButton() 
		
		If IsHasNextStep() == 'NO' Then Exit
			
		Switch DetermineCurrentDialog()
			
		Case 'SelectDestnition'   ;welcome -> license -> SN -> destination
			
			SelectDestnitionDialogTest() 
			
			CliclkNextButton() 
			
			If IsHasNextStep() == 'NO' Then 
				
				Exit
				
			Else
				SelectProgrameFolderDialogTest()
				
				CliclkNextButton()
				
				WaitMoveFile($COPY_FILE_TIME)  
				
				If @OSVersion == 'WIN_VISTA' Then Sleep (90000)
					
				Sleep($iMoreSleepTime)
				
				WinActivate("[CLASS:#32770]")
				
				ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Finish Dialog.jpg', WinGetHandle(''))
				
				FinishedInstall()
				
			EndIf
			
		EndSwitch
		
	Case 'SelectDestnition' ;welcome -> license -> destination
		
		SelectDestnitionDialogTest() 
		
		CliclkNextButton() 
		
		If IsHasNextStep() == 'NO' Then 
			
			Exit
			
		Else
			SelectProgrameFolderDialogTest()
			
			CliclkNextButton()
			
			WaitMoveFile($COPY_FILE_TIME)  
			
			If @OSVersion == 'WIN_VISTA' Then Sleep(90000)
				
			Sleep($iMoreSleepTime)
			
			WinActivate("[CLASS:#32770]")
			
			ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Finish Dialog.jpg', WinGetHandle(''))
			
			FinishedInstall()
		EndIf
		
	EndSwitch
	
Case 'SelectDestnition'   ;welcome -> SelectDestnition 
	
	SelectDestnitionDialogTest() 
	
	CliclkNextButton() 
	
	If IsHasNextStep() == 'NO' Then 
		
		Exit
		
	Else
		SelectProgrameFolderDialogTest()
		
		CliclkNextButton()
		
		WaitMoveFile($COPY_FILE_TIME)  
		
		If @OSVersion == 'WIN_VISTA' Then  Sleep(90000)
			
		Sleep($iMoreSleepTime)
		
		WinActivate("[CLASS:#32770]")
		
		ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, 'INSTALL_Finish Dialog.jpg', WinGetHandle(''))
		
		FinishedInstall()
	EndIf
	
EndSwitch

; Install PM -------------------------------------------------------------------------------
Sleep(20000)

For $i = 1 To 3 
	
	If WinActivate("[CLASS:#32770]") Then
		
		Send('{ENTER}')
		
		Send('{ESC}')
		
		Sleep(20000)
	EndIf	
Next	
; Launch PM and Test -----------------------------------------------------------------------

$PMExePath = GetPMExePath()

If $PMExePath = "" Then 
	
	WriteLog_($LOG_FILE_PATH , 'Script Error: $PMExePath = GetPMExePath() Can not get PM exe path')
	
	Exit
	
EndIf	
	
$hPMHandle = LaunchAP($PMExePath)

If $hPMHandle = '' Then 
	
	WriteLog_($LOG_FILE_PATH , 'Script Error: $hPMHandle = LaunchAP($PMExePath) Can not launch PM')
	
	Exit
	
EndIf	
	
If ControlGetHandle(WinGetHandle("[CLASS:#32770]"), "", "Edit1") <> "" Then
	
	Send("{ENTER}")
	
EndIf

If ProcessExists("Scan Central.exe") Then
	
	ProcessClose("Scan Central.exe")
	
EndIf

Sleep(5000)
	
WinActivate($hPMHandle)

Sleep(500)

CheckHelpCHM($hPMHandle)

CheckAbout($hPMHandle)

CheckMenu($hPMHandle)

CheckScanSettings($hPMHandle)

CheckScanButtonSettings($hPMHandle)

CheckReadMe()

WinActivate($hPMHandle)

CheckStartMenu()

Close_PM_EX($hPMHandle)

;Svae to JPG
SmokingTest1_1_6_Image()

SmokingTest1_1_6_MultiTif()

SmokingTest1_1_6_PDF()

SmokingTest1_1_6_Word()

If @OSVersion == 'WIN_7' Or  @OSVersion == 'WIN_VISTA' Then   ;No XPS function in XP
	
	;Save to XPS
	SmokingTest1_1_7_Image()
	
	SmokingTest1_1_7_MultiTif()
	
	SmokingTest1_1_7_PDF()
	
	SmokingTest1_1_7_Word()
	
	;Print to XPS
	SmokingTest1_1_8_Image()
	
	SmokingTest1_1_8_MultiTif()
	
	SmokingTest1_1_8_Word()	
	
	SmokingTest1_1_8_PDF()
	
EndIf

SmokingTest1_1_10()   ;OCR

;PDF writer
SmokingTest1_1_11_Image()

SmokingTest1_1_11_MultiTif()

SmokingTest1_1_11_PDF()

SmokingTest1_1_11_Word()

Local $bIsHasPageviewer = False

If FileExists(StringReplace(GetPMExePath(), 'prestopm.exe', 'PageViewer')) Then
	
	$bIsHasPageviewer = True
	
EndIf

SmokingTest1_1_12($bIsHasPageviewer)  ;FInd then go to

SmokingTest1_1_13()   ;Stack and copy

SmokingTest1_1_13_()  ;Backup

SmokingTest1_1_14()   ;Zoom

SmokingTest1_1_15()   ;Create new folder

SmokingTest1_1_17()   ;Exoirt to wrapper

SmokingTest1_1_22()   ;Document

SmokingTest1_1_26()   ;Live update

; Launch PM and Test -------------------------------------------------------------------------------

Sleep(5000)

Del_DB()

InitializeStatus()   

; Uninstall PM -------------------------------------------------------------------------------

While ProcessExists('iexplore.exe') 
	
	ProcessClose('iexplore.exe')
	
	Sleep(200)
WEnd

If ProcessExists("Scan Central.exe") Then
	
	ProcessClose("Scan Central.exe")
	
EndIf

If ProcessExists("Pmsb.exe") Then
	
	ProcessClose("Pmsb.exe")
	
	Sleep(200)
EndIf

If ProcessExists ("SmBizcard.exe") Then
	
	ProcessClose ("SmBizcard.exe")
	
	Sleep(200)
EndIf	


$sUninstallerEXEPath = UnistallerEXEPath()

Run($sUninstallerEXEPath)   ;Run uninstaller.

Sleep(25000)

For $i = 0 to 5
	
	CloseRubbishWindow()
	
	Sleep(10000)
	
Next	

If Not ActivateInstallerWindow() Then 
	
	If Not ProcessExists(StringMid($sUninstallerEXEPath,StringInStr($sUninstallerEXEPath,'\', 0, -1) + 1,StringInStr($sUninstallerEXEPath,'.exe') - StringInStr($sUninstallerEXEPath,'\', 0, -1) + 3)) Then
		
		Sleep(60000)
		
		Run($sUninstallerEXEPath) 
		
	EndIf
EndIf

ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "UNINSTALL_Uninstall Confirm.jpg", WinGetHandle(ActivateInstallerWindow()))

ControlClick(ActivateInstallerWindow(), '', 'Button1')

Sleep(35000)


If ControlGetHandle(ActivateInstallerWindow(), '', 'Button1') Then
	
	ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "UNINSTALL_Save DB.jpg", WinGetHandle(ActivateInstallerWindow()))
	
	ControlClick(ActivateInstallerWindow(), '', 'Button1')   ;Save DB dialog
	
EndIf

Sleep(101000)

#cs
$i = 0 

While ControlGetHandle(WinGetHandle("[CLASS:#32770]"), '', 'Button1') <> ''
	
	Sleep(1000)
	
	$i = $i + 1
	
	If $i == 100 Then
		
		ExitLoop
		
	EndIf
	
WEnd
#ce

ScreenCaprureWindow($PERFORM_RESULT_FOLDER_PATH, "UNINSTALL_Finish.jpg", WinGetHandle(ActivateInstallerWindow()))

Send('{ENTER}')

; Uninstall PM -------------------------------------------------------------------------------
